#include <54func.h>

int login(char login_name[], char login_passname[]) {

    if(strcmp(login_name, "yuyihan") != 0) {
        printf("用户名错误！");
        return -1;
    }
    struct spwd* ppswd_real = getspnam("yuyihan");
    struct spwd* ppswd_fake = getspnam(login_passname);
    //printf("encrypted password = %s\n", ppswd->sp_pwdp);

    char salt[] = "$6$fYbE7erB$";
    char* pass_real = crypt(ppswd_real->sp_pwdp, salt);
    char* pass_fake = crypt(ppswd_fake->sp_pwdp, salt);
    if(strcmp(pass_real, pass_fake) != 0) {
        printf("密码错误！");
        return -1;
    }
    // printf("encrypted password = %s\n", crypt(key, salt));

    return 0;
}
